package com.mew.slots.core.game.mymg.room;

import cn.hutool.core.util.RandomUtil;
import com.mew.slots.core.common.game.BaseRoom;
import com.mew.slots.core.game.mymg.roller.Controlline;
import com.mew.slots.core.game.mymg.bo.MymgPlayMsgs;
import com.mew.slots.core.game.mymg.roller.MymgIli;

import java.util.ArrayList;

public class MymgRoom extends BaseRoom {

    final int _SCATTER = 14;
    final int _BONUS = 12;

    int freeType;
    public MymgRoom(int freeType){
        this.freeType = freeType;
        res = new MymgPlayMsgs();
        row = 3;
        col = 5;
        _WILD = 13;
        spes = new ArrayList<Integer>(){{
            add(_SCATTER);
            add(_BONUS);
        }};
        //无法描述
        rate = new int[][]{
                {0, 0,  2, 10, 50},      //眼睛            0
                {0, 0,  2, 10, 50},      //太阳            1
                {0, 0,  2, 10, 50},      //公平秤          2
                {0, 0,  2, 10, 50},      //金字塔          3


                {0, 0, 10, 30, 150},      //小青           4
                {0, 0, 10, 30, 150},      //小蓝           5
                {0, 0, 10, 30, 150},      //小黄           6
                {0, 0, 10, 30, 150},      //小红           7

                {0, 0, 15, 50, 300},      //大青           8
                {0, 0, 15, 50, 300},      //大蓝           9
                {0, 0, 15, 50, 300},      //大黄           10
                {0, 0, 15, 50, 300},      //大青           11

                {0, 0,  0,   0,  0},      //BONUS          12
                {0, 0,  0,   0,  0},      //WILD           13
                {0, 0,  0,   0,  0},      //SCATTER        14
        };
        alllines=new int[][]{
                {5,6,7,8,9},
                {0,1,2,3,4},
                {10,11,12,13,14},
                {0,6,12,8,4},
                {10,6,2,8,14},
                {5,1,7,13,9},
                {5,11,7,3,9},
                {0,1,7,13,14},
                {10,11,7,3,4},
                {0,6,2,8,4},
                {10,6,12,8,14},
                {5,1,2,3,9},
                {5,11,12,13,9},
                {0,6,7,8,4},
                {10,6,7,8,14},
                {5,6,2,8,9},
                {5,6,12,8,9},
                {5,1,7,3,9},
                {5,11,7,13,9},
                {0,1,2,8,14},
                {10,11,12,8,4},
                {0,6,12,13,14},
                {10,6,2,3,4},
                {5,6,7,3,14},
                {5,6,7,13,4},
                {0,6,7,8,14},
                {10,6,7,8,4},
                {10,11,7,3,9},
                {0,1,7,13,9},
                {10,6,12,13,14},
                {0,6,2,3,4},
                {0,6,12,8,9},
                {10,6,2,8,9},
                {5,1,7,3,4},
                {5,11,7,13,14},
                {0,6,7,8,9},
                {10,6,7,8,9},
                {5,1,2,3,4},
                {5,11,12,13,14},
                {5,6,7,8,4},
                {5,6,7,8,14},
                {0,1,7,3,4},
                {10,11,7,13,14},
                {0,1,2,8,4},
                {10,11,12,8,14},
                {5,6,2,3,4},
                {5,6,12,13,14},
                {0,1,7,8,4},
                {10,11,7,8,14},
                {10,6,2,8,4}
        };
    }
    @Override
    public void getLinesXml(){

        if (controlType>0){
            endSlots = control();
        } else {
            endSlots = rollerXml.getLineInts(free?1:0,rollerID);
        }
        res.endSlots=endSlots;
//        if(free){
//            replaceFreeIcon();
//        }
    }

    @Override
    public int[] getIliEndSlots(){
        if(free){
            return iliXml.getSpeints("mfree"+freeType);
        }
        return iliXml.getLineints(0,rollerID,in,0);
    }

    private void replaceFreeIcon(){
        for (int c = 1; c < col-1; c++) {
            for (int r = 0; r < row; r++) {
                endSlots[r*5+c] = freeType;
            }
        }
    }

    @Override
    public void freeBouns(){
        //
        MymgPlayMsgs pmres = (MymgPlayMsgs) res;
        int randomRate = RandomUtil.randomInt(1,4);
        pmres.setRate(randomRate);
        res.setMultiple(pmres.getMultiple()*randomRate);

        int scatterNum = fsdb(_SCATTER);
        if(scatterNum>2){
            pmres.setFree((byte)1);
            pmres.setFreeNumber(10);
            pmres.setFreeType(RandomUtil.randomInt(8,12));
        }
        int bonusNum = fsdb(_BONUS);
        if(bonusNum>2){
            res.setBouns(1);
        }
    }

    @Override
    public int[] control(){
        MymgIli instance = MymgIli.getInstance();
        switch (controlType) {
            case 1:
                return instance.getSpeints("21-23");
            case 2:
                return instance.getSpeints("free");
            case 3:
                return instance.getSpeints("bonus");
            default:
                return instance.getSpeints("0-0");
        }
    }

   /* @Override
    public int[] control(){
        Controlline controlline=new Controlline();
        switch (controlType) {
            case 1:
                return bigwin();
            case 2:
                return controlline.free();
            case 3:
                return controlline.bonus();
            default:
                return controlline.empty();
        }
    }*/
}
